package com.company.线程.线程池;

import com.company.线程.推荐线程池.Pools;

import java.util.concurrent.*;

/**
 * @author gyhstart
 * @create 2021/5/11 - 22:39
 **/
public class Test {
    public static void main(String[] args) {

        // newFixedThreadPool 新的固定线程池
        for (int i = 0; i < 10; i++) {
            Executors.newFixedThreadPool(3).execute(() -> System.out.println("Id: " + Thread.currentThread().getId() + " ,线程:" + Thread.currentThread().getName()));
        }

        // newSingleThreadExecutor 新的单线程执行器
        ExecutorService service = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 10; i++) {
            final int index = i;
            service.execute(() -> {
                System.out.println("序号" + index + " Id: " + Thread.currentThread().getId() + " ,线程:" + Thread.currentThread().getName());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
